package com.sisgesbyte.dao.tecnico;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Iterator;

import org.apache.poi.hssf.usermodel.HSSFRow;

import java.util.List;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.hssf.usermodel.HSSFCell;

import java.util.ArrayList;

public class LeerExcel {

	public static void main(String[] args) {
		 String filename = "C:\\desarrollo\\otros\\erp_zeus\\FORMATOS_EXCEL_DATA\\formato_subir_clientes.xls";
		 List sheetData = new ArrayList();
		 FileInputStream fis = null;
		 try {
			 fis = new FileInputStream(filename);
			 HSSFWorkbook workbook = new HSSFWorkbook(fis);
			 HSSFSheet sheet = workbook.getSheetAt(0);
			 Iterator rows = sheet.rowIterator();	
			 while (rows.hasNext()) {
				 HSSFRow row = (HSSFRow) rows.next();
				 Iterator cells = row.cellIterator();
				 List data = new ArrayList();
				 while (cells.hasNext()) {
					 HSSFCell cell = (HSSFCell) cells.next();	
					 data.add(cell);
				 }
				 sheetData.add(data);
			 }
		 } catch (IOException e) {
			 e.printStackTrace();
		 } finally {
			 if (fis != null) {
				 try {
					fis.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			 }
		 }
		 //System.out.println("-- "+sheetData);
		 showExelData(sheetData);

	}
	private static void showExelData(List sheetData) {
		for (int i = 1; i < sheetData.size(); i++) {
			List list = (List) sheetData.get(i);
			if(list.toString().replace("[", "").replace("]", "").length() > 0){
				String[] fila = null;
					try{
						fila = list.toString().replace("[", "").replace("]", "").split(",");
					}catch(Exception e){
						System.out.println("Error al tratar de leer la fila "+ e);
					}
					System.out.println(fila[3].toString().trim());
					if(fila[3].toString().trim() == "-"){
						System.out.println("Ingresa");
					}else{
						System.out.println("No encuentra");
					}
				System.out.println(fila[3]);
				
				
			}
			
		}
	}
}
